package com.geor.gcv.ict.train;

import java.util.List;
import java.util.Map;

import org.opencv.core.Mat;

/**
 * ann实现类
 * 
 * @author lusongnan
 *
 */
public class TrainerANNGraphic extends TrainerAbstract {
	Ml ml;

	@Override
	public void train(Mat trainData, Mat label, String out) {
		ml.train(trainData, label, out);
	}

	@Override
	public Mat[] createTrainDataAndLabel(Map<String, List<Mat>> mapMats) {

		Mat trainData = new Mat(TOTAL, species, TYPE);
		Mat labels = new Mat(TOTAL, species, TYPE);
		int row_count = 0;

		for (String i : mapMats.keySet()) {
			for (int row = 0; row < labels.rows(); row++) {
				for (int col = 0; col < labels.cols(); col++) {
					labels.put(row, col, Integer.parseInt(i));
				}
			}
			List<Mat> mats = mapMats.get(i);
			for (int n = 0; n < mats.size(); n++) {
				int col_count = 0;
				for (int i1 = 0; i1 < HEIGHT; i1++) {
					for (int j1 = 0; j1 < WIDTH; j1++) {
						trainData.put(row_count, col_count++, (float) mats.get(n).get(i1, j1)[0]);
					}
				}
				row_count++;
			}
		}
		Mat mats[] = { trainData, labels };
		return mats;
	}

}
